package com.example.druiddb.util;

import com.alibaba.druid.filter.config.ConfigTools;

/**
 * 数据库 密码加密
 *
 * @ClassName DBPassword
 * @Author xiaojiang
 * @Date 2021/9/13 下午 15:04
 */
public class DBPassword {

    public static void main(String[] args) throws Exception{
        String password = "root";
        System.out.println("明文密码: " + password);

        String[] keyPair = ConfigTools.genKeyPair(512);
        //私钥
        String privateKey = keyPair[0];
        //公钥
        String publicKey = keyPair[1];
        //用私钥加密后的密文
        password = ConfigTools.encrypt(privateKey, password);
        System.out.println("privateKey:" + privateKey);
        System.out.println("publicKey:" + publicKey);
        System.out.println("password:" + password);
        String decryptPassword = ConfigTools.decrypt(publicKey, password);
        System.out.println("解密后:" + decryptPassword);

    }

}
